import BaseChannel from "./BaseChannel";
import { compareVersion } from "../SDKDefine";
let zsSdk = require("../../lib/zs.sdk");
export default class ZSChannel extends BaseChannel {
    openID = ''
    verson = '1.0';
    zsConfig = {
        zs_version: '1.0',
        zs_native_click_switch: 0,
        zs_native_limit: 0,
        zs_native_touch_switch: 0,
        zs_native_show_time_limit: 20 //秒
    }
    constructor(id){
        super(id)
        this.login()
    }

    login() {
        zsSdk.login((openid) => {
            this.loadConfig()
            console.log(' msg ', openid)
            this.openID = openid

            // zsSdk.init(this.openID)

        }, (err) => {
            console.log('login error ', err)
            setTimeout(() => {
                this.login()
            }, 3000);
        })
    }

    getNativeDuration() {
        return this.zsConfig.zs_native_show_time_limit;
    }

    loadConfig() {
        zsSdk.loadCfg((result) => {
            this.zsConfig = result;
            console.log(' result === ', result)
        }, (err) => {
            console.log(' err === ', err)
            setTimeout(() => {
                this.loadConfig()
            }, 3000);
        });
    }

    isOpenNativeErrorClick() {
        console.log('isOpenNativeErrorClick this.verson  ==  ', this.verson)
        return compareVersion(this.verson, this.zsConfig.zs_version) == 1
            && this.zsConfig.zs_native_click_switch == 1
    }

    /**
     * 是否打开弹出广告界面
     */
    isOpenNativeView() {
        return compareVersion(this.verson, this.zsConfig.zs_version) == 1
            && this.zsConfig.zs_native_limit == 1
    }

    isOpenTouchError() {
        return compareVersion(this.verson, this.zsConfig.zs_version) == 1
            && this.zsConfig.zs_native_touch_switch == 1
    }
}